﻿using System;
using System.Collections.ObjectModel;
using System.Device.Location;
using System.Runtime.Serialization;

namespace SydEnergiPrototype.Model
{
    public class Cabinets : ObservableCollection<ICabinet> {}

    [DataContract]
    public class Cabinet : ICabinet
    {
        [DataMember]
        private Entries _entryCollection;
        public Entries EntryCollection
        {
            get
            {
                if(_entryCollection == null)
                    _entryCollection = new Entries();

                return _entryCollection;
            }
            set
            {
                _entryCollection = value;
            }
        }
        [DataMember]
        private string _id;
        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }

        [DataMember]
        private IAddress _cabinetAddress;
        public IAddress CabinetAddress
        {
            get { return _cabinetAddress; }
            set { _cabinetAddress = value; }
        }

        [DataMember]
        private GeoCoordinate _cabinetPosition;
        public GeoCoordinate CabinetPosition
        {
            get { return _cabinetPosition; }
            set { _cabinetPosition = value; }
        }

        public Cabinet()
        {

        }

        public Cabinet(string id, IAddress address, GeoCoordinate position)
        {
            if(string.IsNullOrEmpty(id) || string.IsNullOrWhiteSpace(id))
                throw new ArgumentNullException("id");

            _id = id;

            if(address == null)
                throw new ArgumentNullException("address");

            _cabinetAddress = address;

            if(position == null)
                throw new ArgumentNullException("position");

            if(Double.IsNaN(position.Latitude) || Double.IsNaN(position.Longitude))
                throw new ArgumentOutOfRangeException("position");

            _cabinetPosition = position;
        }
    }
}
